package gold.digger;

import gold.utils.InputUtil;
import gold.vo.TreeNode;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1038 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public TreeNode bstToGst(TreeNode root) {
            bstToGstRecur(root, 0);
            return root;
        }

        public int bstToGstRecur(TreeNode root, int prevSum) {
            if (null == root) return prevSum;
            int rightSum = bstToGstRecur(root.right, prevSum);
            root.val += rightSum;
            return bstToGstRecur(root.left, root.val);
        }
    }

    public void run() {
        System.out.println(new Solution().bstToGst(TreeNode.createTree("[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]")));
    }

    public static void main(String[] args) throws Exception {
        LC1038 an = new LC1038();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
